package com.windowes.weichang.service;

import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.component.redis.RedisService;
import com.windowes.weichang.dao.WUserMapper;
import com.windowes.weichang.pojo.WUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/5/31 下午11:57
 * @description:
 *
 **/
@Service
public class UserCoreService {


    @Autowired
    WUserMapper userMapper;
    @Autowired
    RedisService redisService;

    /**
     * 根据手机号查询用户信息
     *
     * @param phone
     * @return
     */
    public ServerResponse<WUser> getUserByPhone(String phone) {
        //从缓存中获取
        WUser wUser = redisService.getUser(phone);
        if (wUser != null) {
            return ServerResponse.createBySuccess("查询成功！", wUser);
        }
        wUser = userMapper.selectByPhone(phone);
        if (wUser == null) {
            return ServerResponse.createByErrorMessage("未找到用户！");
        }
        return ServerResponse.createBySuccess("查询成功！", wUser);
    }
}
